package com.morty.product.controller;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.morty.product.controllor.ProductControllerApi;
import com.morty.product.entity.Product;
import com.morty.product.service.ProductService;
import com.morty.user.vo.UserLockVo;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.morty.product.vo.ProductVo;

import javax.annotation.Resource;

@RestController
@RequestMapping("/product/product")
public class ProductController implements ProductControllerApi {

    @Resource
    private ProductService productService;

    @Override
    @SentinelResource("getProductById")
    public ProductVo getProductById(String proId) {
        ProductVo productVo = new ProductVo();
        Product product= productService.getProductById(proId);
        productVo = BeanUtil.toBean(product,ProductVo.class);
        return productVo;
    }

    @Override
    public int insertProduct(ProductVo productVo) throws Exception {
        Product product= new Product();
        product = BeanUtil.toBean(productVo,Product.class);
        return productService.insertProduct(product);
    }

    @Override
    public int updateProduct(ProductVo productVo) {
        Product product= new Product();
        product = BeanUtil.toBean(productVo,Product.class);
        return productService.updateProduct(product);
    }

    @Override
    public String testSeata(){
        return productService.testSeata();
    }

    @Override
    public String testSeataLock(){
        return productService.testSeataLock();
    }

    @Override
    public String testRedis(){
        return productService.testRedis();
    }

    @Override
    public String testRedisUtil(String lock){
        return productService.testRedisUtil(lock);
    }
}
